﻿<UserControl x:Class="SABnzbdNET.Views.ServerInfoView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:comm="clr-namespace:SABnzbdNET.Commands"
             xmlns:conv="clr-namespace:SABnzbdNET.Converters"
             mc:Ignorable="d" d:DesignHeight="330" d:DesignWidth="500">
    <UserControl.Resources>
        <conv:IsCheckedConverter x:Key="IsCheckedConverter" />
        <conv:CommandParameterConverter x:Key="CommandParameterConverter" />
        <conv:ProcessingConverter x:Key="ProcessingConverter" />
        <comm:CommandReference x:Key="StartCommandReference" Command="{Binding Path=StartCommand}" />
        <comm:CommandReference x:Key="PauseCommandReference" Command="{Binding Path=PauseCommand}" />
        <comm:CommandReference x:Key="DeleteCommandReference" Command="{Binding Path=DeleteCommand}" />
        <comm:CommandReference x:Key="ProcessingCommandReference" Command="{Binding Path=ProcessingCommand}" />
        <comm:CommandReference x:Key="PriorityCommandReference" Command="{Binding Path=PriorityCommand}" />
        <ContextMenu x:Key="DownloadItemContextMenu">
            <MenuItem Header="Resume individual download" Command="{StaticResource StartCommandReference}" CommandParameter="{Binding}" />
            <MenuItem Header="Pause individual download" Command="{StaticResource PauseCommandReference}" CommandParameter="{Binding}" />
            <MenuItem Header="Delete individual download" Command="{StaticResource DeleteCommandReference}" CommandParameter="{Binding}" />
            <MenuItem Header="Change processing">
                <MenuItem Header="Download" IsCheckable="True" Command="{StaticResource ProcessingCommandReference}">
                    <MenuItem.IsChecked>
                        <MultiBinding Converter="{StaticResource IsCheckedConverter}" Mode="OneWay" ConverterParameter="'processing'">
                            <Binding />
                            <Binding Path="Header" RelativeSource="{RelativeSource Self}" />
                        </MultiBinding>
                    </MenuItem.IsChecked>
                    <MenuItem.CommandParameter>
                        <MultiBinding Converter="{StaticResource CommandParameterConverter}" ConverterParameter="'processing'">
                            <Binding />
                            <Binding Path="Header" RelativeSource="{RelativeSource Self}" />  
                        </MultiBinding>
                    </MenuItem.CommandParameter>
                </MenuItem>
                <MenuItem Header="+Repair" IsCheckable="True" Command="{StaticResource ProcessingCommandReference}">
                    <MenuItem.IsChecked>
                        <MultiBinding Converter="{StaticResource IsCheckedConverter}" Mode="OneWay" ConverterParameter="'processing'">
                            <Binding />
                            <Binding Path="Header" RelativeSource="{RelativeSource Self}" />
                        </MultiBinding>
                    </MenuItem.IsChecked>
                    <MenuItem.CommandParameter>
                        <MultiBinding Converter="{StaticResource CommandParameterConverter}" ConverterParameter="'processing'">
                            <Binding />
                            <Binding Path="Header" RelativeSource="{RelativeSource Self}" />
                        </MultiBinding>
                    </MenuItem.CommandParameter>
                </MenuItem>
                <MenuItem Header="+Unpack" IsCheckable="True" Command="{StaticResource ProcessingCommandReference}">
                    <MenuItem.IsChecked>
                        <MultiBinding Converter="{StaticResource IsCheckedConverter}" Mode="OneWay" ConverterParameter="'processing'">
                            <Binding />
                            <Binding Path="Header" RelativeSource="{RelativeSource Self}" />
                        </MultiBinding>
                    </MenuItem.IsChecked>
                    <MenuItem.CommandParameter>
                        <MultiBinding Converter="{StaticResource CommandParameterConverter}" ConverterParameter="'processing'">
                            <Binding />
                            <Binding Path="Header" RelativeSource="{RelativeSource Self}" />
                        </MultiBinding>
                    </MenuItem.CommandParameter>
                </MenuItem>
                <MenuItem Header="+Delete" IsCheckable="True" Command="{StaticResource ProcessingCommandReference}">
                    <MenuItem.IsChecked>
                        <MultiBinding Converter="{StaticResource IsCheckedConverter}" Mode="OneWay" ConverterParameter="'processing'">
                            <Binding />
                            <Binding Path="Header" RelativeSource="{RelativeSource Self}" />
                        </MultiBinding>
                    </MenuItem.IsChecked>
                    <MenuItem.CommandParameter>
                        <MultiBinding Converter="{StaticResource CommandParameterConverter}" ConverterParameter="'processing'">
                            <Binding />
                            <Binding Path="Header" RelativeSource="{RelativeSource Self}" />  
                        </MultiBinding>
                    </MenuItem.CommandParameter>
                </MenuItem>
            </MenuItem>
            <MenuItem Header="Change priority">
                <MenuItem Header="Low" IsCheckable="True" Command="{StaticResource PriorityCommandReference}">
                    <MenuItem.IsChecked>
                        <MultiBinding Converter="{StaticResource IsCheckedConverter}" Mode="OneWay" ConverterParameter="'priority'">
                            <Binding />
                            <Binding Path="Header" RelativeSource="{RelativeSource Self}" />
                        </MultiBinding>
                    </MenuItem.IsChecked>
                    <MenuItem.CommandParameter>
                        <MultiBinding Converter="{StaticResource CommandParameterConverter}" ConverterParameter="'priority'">
                            <Binding />
                            <Binding Path="Header" RelativeSource="{RelativeSource Self}" />
                        </MultiBinding>
                    </MenuItem.CommandParameter>
                </MenuItem>
                <MenuItem Header="Normal" IsCheckable="True" Command="{StaticResource PriorityCommandReference}">
                    <MenuItem.IsChecked>
                        <MultiBinding Converter="{StaticResource IsCheckedConverter}" Mode="OneWay" ConverterParameter="'priority'">
                            <Binding />
                            <Binding Path="Header" RelativeSource="{RelativeSource Self}" />
                        </MultiBinding>
                    </MenuItem.IsChecked>
                    <MenuItem.CommandParameter>
                        <MultiBinding Converter="{StaticResource CommandParameterConverter}" ConverterParameter="'priority'">
                            <Binding />
                            <Binding Path="Header" RelativeSource="{RelativeSource Self}" />
                        </MultiBinding>
                    </MenuItem.CommandParameter>
                </MenuItem>
                <MenuItem Header="High" IsCheckable="True" Command="{StaticResource PriorityCommandReference}">
                    <MenuItem.IsChecked>
                        <MultiBinding Converter="{StaticResource IsCheckedConverter}" Mode="OneWay" ConverterParameter="'priority'">
                            <Binding />
                            <Binding Path="Header" RelativeSource="{RelativeSource Self}" />
                        </MultiBinding>
                    </MenuItem.IsChecked>
                    <MenuItem.CommandParameter>
                        <MultiBinding Converter="{StaticResource CommandParameterConverter}" ConverterParameter="'priority'">
                            <Binding />
                            <Binding Path="Header" RelativeSource="{RelativeSource Self}" />
                        </MultiBinding>
                    </MenuItem.CommandParameter>
                </MenuItem>
            </MenuItem>
        </ContextMenu>
        <ToolTip x:Key="DownloadItemTooltip">
            <Grid Margin="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="100" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="20" />
                    <RowDefinition Height="20" />
                    <RowDefinition Height="20" />
                    <RowDefinition Height="20" />
                    <RowDefinition Height="20" />
                    <RowDefinition Height="20" />
                    <RowDefinition Height="20" />
                    <RowDefinition Height="20" />
                    <RowDefinition Height="20" />
                </Grid.RowDefinitions>
                <TextBlock Text="Title:" Grid.Column="0" Grid.Row="0" />
                <TextBlock Text="{Binding Title}" VerticalAlignment="Top" HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="0" />
                <TextBlock Text="Status:" Grid.Column="0" Grid.Row="1" />
                <TextBlock Text="{Binding Status}" VerticalAlignment="Top" HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="1" />
                <TextBlock Text="Category:" Grid.Column="0" Grid.Row="2" />
                <TextBlock Text="{Binding Category}" VerticalAlignment="Top" HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="2" />
                <TextBlock Text="Size:" Grid.Column="0" Grid.Row="3" />
                <TextBlock Text="{Binding Size, StringFormat=N2}" Grid.Column="1" Grid.Row="3" />
                <TextBlock Text="Remaining:" Grid.Column="0" Grid.Row="4" />
                <TextBlock Text="{Binding SizeRemaining, StringFormat=N2}" Grid.Column="1" Grid.Row="4" />
                <TextBlock Text="Time left:" Grid.Column="0" Grid.Row="5" />
                <TextBlock Text="{Binding TimeLeft}" Grid.Column="1" Grid.Row="5" />
                <TextBlock Text="Eta:" Grid.Column="0" Grid.Row="6" />
                <TextBlock Text="{Binding Eta}" Grid.Column="1" Grid.Row="6" />
                <TextBlock Text="Processing:" Grid.Column="0" Grid.Row="7" />
                <TextBlock Text="{Binding Processing, Converter={StaticResource ProcessingConverter}, Mode=OneWay}" VerticalAlignment="Top" HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="7" />
                <TextBlock Text="Priority:" Grid.Column="0" Grid.Row="8" />
                <TextBlock Text="{Binding Priority}" VerticalAlignment="Top" HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="8" />
            </Grid>
        </ToolTip>
    </UserControl.Resources>
    <Grid>
        <GroupBox Name="grpStatus" HorizontalAlignment="Stretch" VerticalAlignment="Top" Header="Server status">
            <Grid Margin="5">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="100" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="20" />
                    <RowDefinition Height="20" />
                    <RowDefinition Height="20" />
                    <RowDefinition Height="20" />
                    <RowDefinition Height="20" />
                    <RowDefinition Height="20" />
                    <RowDefinition Height="20" />
                </Grid.RowDefinitions>
                <Image HorizontalAlignment="Right" Name="imgBackground" Opacity="0.15" Stretch="Uniform" VerticalAlignment="Stretch" Grid.Column="1" Grid.Row="0" Grid.RowSpan="7">
                    <Image.Source>
                        <BitmapImage UriSource="/SABnzbdNET;component/Graphics/SABnzbd.jpg"></BitmapImage>
                    </Image.Source>
                </Image>
                <TextBlock HorizontalAlignment="Left" Grid.Column="0" Grid.Row="0">Server</TextBlock>
                <TextBlock  VerticalAlignment="Top" HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="0">
                    <Hyperlink Command="{Binding Path=LaunchBrowserCommand}">
                        <Run Text="{Binding Source={StaticResource Settings}, Path=Default.ServerPath}" />
                    </Hyperlink>
                </TextBlock>
                <TextBlock HorizontalAlignment="Left" Grid.Column="0" Grid.Row="1">Status</TextBlock>
                <TextBlock HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="1" Text="{Binding Path=ServerInfo.Status}"></TextBlock>
                <TextBlock HorizontalAlignment="Left" Grid.Column="0" Grid.Row="2">Current title</TextBlock>
                <TextBlock HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="2" Text="{Binding Path=FirstJob.Title}"></TextBlock>
                <TextBlock HorizontalAlignment="Left" Grid.Column="0" Grid.Row="3">Download speed</TextBlock>
                <TextBlock HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="3" Text="{Binding Path=DownloadSpeed}"></TextBlock>
                <TextBlock HorizontalAlignment="Left" Grid.Column="0" Grid.Row="4">Total progress</TextBlock>
                <ProgressBar Height="15" Margin="0,0,150,0" Grid.Column="1" Grid.Row="4" Name="progressBar" VerticalAlignment="top" Value="{Binding Path=TotalProgressPercent}">
                    <ProgressBar.ToolTip>
                        <ToolTip Content="{Binding Path=TotalProgressPercent}" ContentStringFormat="{}{0}%" />
                    </ProgressBar.ToolTip>
                </ProgressBar>
                <TextBlock HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="4" Text="{Binding Path=TotalProgress}" FontSize="10" />
                <TextBlock HorizontalAlignment="Left" Grid.Column="0" Grid.Row="5">Time left</TextBlock>
                <TextBlock HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="5" Text="{Binding Path=TimeLeft}"></TextBlock>
                <TextBlock HorizontalAlignment="Left" Grid.Column="0" Grid.Row="6">Disk space</TextBlock>
                <TextBlock HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="6" Text="{Binding Path=DiskSpace}"></TextBlock>
            </Grid>
        </GroupBox>
        <GroupBox HorizontalAlignment="Stretch" Height="165" VerticalAlignment="Bottom" Header="Current downloads" >
            <Grid>
                <ListView Margin="0,0,0,0" VerticalAlignment="Stretch" ItemsSource="{Binding Path=ServerInfo.Jobs}">
                    <ListView.ItemContainerStyle>
                        <Style TargetType="{x:Type ListViewItem}">
                            <Setter Property="ContextMenu" Value="{StaticResource DownloadItemContextMenu}"/>
                            <Setter Property="ToolTip" Value="{StaticResource DownloadItemTooltip}"/>
                            <Setter Property="ToolTipService.ShowDuration" Value="30000"/>
                        </Style>
                    </ListView.ItemContainerStyle>
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <Grid Margin="5" Width="515" HorizontalAlignment="Stretch">
                                <TextBlock Margin="0,0,50,0" Text="{Binding Title}" VerticalAlignment="Top" HorizontalAlignment="Stretch" />
                                <TextBlock Margin="0,0,0,0" Text="{Binding Status}" VerticalAlignment="Top" HorizontalAlignment="Right" FontSize="10" />
                                <ProgressBar Margin="0,20,0,0" Height="15" Width="300" Value="{Binding Progress}" VerticalAlignment="Top" HorizontalAlignment="Left">
                                    <ProgressBar.ToolTip>
                                        <ToolTip Content="{Binding Progress}" ContentStringFormat="{}{0}%" />
                                    </ProgressBar.ToolTip>
                                </ProgressBar>
                                <StackPanel Margin="5,20,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="290" Orientation="Horizontal" FlowDirection="LeftToRight">
                                    <StackPanel.ToolTip>
                                        <ToolTip Content="{Binding Progress}" ContentStringFormat="{}{0}%" />
                                    </StackPanel.ToolTip>
                                    <TextBlock Text="{Binding SizeRemaining, StringFormat=N2}" FontSize="10" />
                                    <TextBlock Text=" MB of " FontSize="10" />
                                    <TextBlock Text="{Binding Size, StringFormat=N2}" FontSize="10" />
                                    <TextBlock Text=" MB left " FontSize="10" />
                                </StackPanel>
                                <StackPanel Margin="205,20,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Top" Orientation="Horizontal" FlowDirection="RightToLeft">
                                    <TextBlock Text="{Binding Eta}" FontSize="10" />
                                    <TextBlock Text=" :Eta ." FontSize="10" />
                                    <TextBlock Text="{Binding TimeLeft}" FontSize="10" />
                                    <TextBlock Text=" :Time left" FontSize="10" />
                                </StackPanel>
                            </Grid>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </Grid>
        </GroupBox>
    </Grid>
</UserControl>
